import os
import logging

from agent.common.tools import ConfigFile
from agent.feature.base import Feature

logger = logging.getLogger('common')

class Affinity(Feature):
    __domain__ = "systemd" 
    __feature__ = "cpu_affinity"
    
    def __init__(self):
        super().__init__(self.__domain__, self.__feature__)
        
        self.systemd_config = "/etc/systemd/system.conf"
        if not os.path.exists(self.systemd_config):
            raise Exception("file {} don't exists.".format(self.systemd_config))
        self.config_file = ConfigFile(self.systemd_config)

    def set_value(self, value):
        self.config_file.writeValue(key="CPUAffinity", value = value)
        self.config_file.removeDuplicate()

    def get_value(self):
        return self.config_file.readValue(key = "CPUAffinity")